package com.bing.format;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by kaibb on 15-12-8.
 */
public class JsonDate extends JsonSerializer<Date> {
    private static final String TIMES="yyyy-MM-dd HH:mm:ss";

    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        SimpleDateFormat dateFormat=new SimpleDateFormat(TIMES);
        String value = dateFormat.format(date);
        gen.writeString(value);
    }
}
